#include "simple_sp.h"

#include <limits>

using std::string;
using std::vector;

std::string FindTheNearest(const SimpleDictionary& dictionary, const std::string& word)
{
    int minDistance = std::numeric_limits<int>::max();
    SimpleDictionary::const_iterator bestWord;

    for (SimpleDictionary::const_iterator it = dictionary.begin();
         it != dictionary.end(); ++it)
    {
        int distance = levenshtein_distance((*it), word);
        if (distance < minDistance)
        {
            minDistance = distance;
            bestWord = it;
        }
    }

    return (*bestWord);
}
